 /**
 * 逻辑、功能相关描述:装修监管
 *
 * @author yandawei 编写日期：2008-12-19
 */
package com.ce.pms.renovation.web;

import java.util.List;

import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.house.service.IBuildingService;
import com.ce.pms.renovation.service.IRenovateManageService;
import com.ce.pms.renovation.service.IRenovateSupervisionService;
import com.ce.pms.renovation.vo.ReformVO;
import com.ce.pms.renovation.vo.RenovateRequisitionVO;
import com.ce.pms.renovation.vo.RenovateViolationConditionVO;
import com.ce.pms.renovation.vo.RenovateViolationVO;
import com.ce.util.BlankUtil;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.annotation.Scope;
import com.sitechasia.webx.core.support.Page;

/**
 * @author yandawei
 *
 */
public class RenovateViolationAction extends PmsBaseAction {

	private IRenovateSupervisionService renovateSupervisionService;
	private IBuildingService buildingService;
	private IRenovateManageService renovateManageService;
	/***
	 * 功能描述:  初始化装修监管主界面<br>
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initRenovateViolationMain(){
		List buildingList = buildingService.getAllBuildingList();
		setAttribute("buildList", buildingList);
		return "renovateViolationMain";
	}

	/***
	 * 功能描述: 初始化违规登记高级查询 <br>
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initRenovateViolationSeniorSearch(){
		List buildingList = buildingService.getAllBuildingList();
		setAttribute("buildList", buildingList);
		return "renovateViolationSearch";
	}

	/***
	 * 功能描述: 违规登记查询 <br>
	 * @param queryCondition
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String queryRenovateViolationInfo(
			@Read RenovateViolationConditionVO queryCondition,
			@Read(key = "ec_p", defaultValue = "1") Integer pageNO,
			@Read(key = "ec_crd",defaultValue = "15")Integer pageSize){
		queryCondition.setPageNo(pageNO);
		queryCondition.setPageSize(pageSize);
		Page page = renovateSupervisionService.queryRenovateViolations(queryCondition);
		if(!BlankUtil.isBlank(page)){
			setAttribute("renovateViolationList", page.getResult());
			setAttribute("totalRows",Integer.valueOf(String.valueOf(page.getTotalCount())));
		}else{
			setAttribute("totalRows",new Integer(0));
		}
		return "renovateViolationList";
	}

	/** 功能描述: 整改记录判断 <br>
	 * @param id
	 * Create author:许心炜 <br>
	 * Create on:2009-1-13  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	public void hasReforms(@Read(key="renovateViolationId")Long id) {
		List<ReformVO> list = renovateSupervisionService.getReforms(id);
		if (list.size() > 0) {
			this.renderText("false");
		} else {
			this.renderText("true");
		}
	}

	/** 功能描述: 通过状态的整改记录判断 <br>
	 * @param id
	 * Create author:许心炜 <br>
	 * Create on:2009-1-13  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	public void hasPassReform(@Read(key="renovateViolationId")Long id) {
		ReformVO reformVO= renovateSupervisionService.getPassReform(id);
		if (reformVO == null) {
			this.renderText("true");
		} else {
			this.renderText("false");
		}
	}

	/***
	 * 功能描述:  初始化违规登记列表<br>
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initRenovateViolationList(){
		setRenoViolateConditionCache(new RenovateViolationConditionVO());
		setAttribute("totalRows",new Integer(0));
		return "renovateViolationList";
	}

	/***
	 * 功能描述:  刷新违规登记列表<br>
	 * @param pageNO
	 * @param pageSize
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String queryRenovateViolationList(
			@Read(key = "ec_p", defaultValue = "1") Integer pageNO,
			@Read(key = "ec_crd",defaultValue = "15")Integer pageSize){
		RenovateViolationConditionVO queryCondition = getRenoViolateConditionFromCache();
		if(queryCondition == null) {
			return initRenovateViolationList();
		}else {
			return queryRenovateViolationInfo(queryCondition, pageNO, pageSize);
		}
	}

	/**
	 * 功能描述:  设置查询条件<br>
	 * @param conditionVO
	 * Create author:yandawei <br>
	 * Create on:2008-12-23  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void setRenoViolateConditionCache(@Read	RenovateViolationConditionVO conditionVO) {
		setAttribute("condition", conditionVO,Scope.SESSION);
	}

	/**
	 * 功能描述: 获取缓存中的查询条件 <br>
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-23  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	private RenovateViolationConditionVO getRenoViolateConditionFromCache(){
		RenovateViolationConditionVO obj = (RenovateViolationConditionVO) getAttribute("condition",Scope.SESSION);
		return obj;
	}

	/***
	 * 功能描述: 初始化新增违规登记 <br>
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initRenovateViolationAdd(){
		setAttribute("flag", "add");
		RenovateViolationVO renovateViolationDO = new RenovateViolationVO();
		setAttribute("violation", renovateViolationDO);
		return "renovateViolationEdit";
	}


	/** 功能描述:判断是否已经有了验收申请了  <br>
	 * @param licenceId
	 * Create author:许心炜 <br>
	 * Create on:2009-1-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	public void isViolation(@Read(key="licenceId")Long licenceId){
		if(renovateSupervisionService.isViolation(licenceId)) {
			this.renderText("true");
		}else {
			this.renderText("false");
		}
	}

	/** 功能描述: 验证房号 <br>
	 * @param houseId
	 * Create author:许心炜 <br>
	 * Create on:2009-1-14  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	*/
	public void validateHouse(@Read(key="houseId")Long houseId) {

		try {
				RenovateRequisitionVO  renovateRequisitionVO = renovateManageService.getRequisitionOutline(houseId);
				renovateSupervisionService.isViolation(renovateRequisitionVO.getRenovateLicenceId());
				this.renderText("true");
		}catch (BusinessException e) {
			this.renderText(super.getLocaleMessage(e.getMessage()));
		}
	}

	/**
	 * 功能描述:  根据房间ID带出装修申请信息<br>
	 * @param houseId
	 * Create author:yandawei <br>
	 * Create on:2008-12-22  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void loadRenovateRequisiteInfo(@Read(key="houseId")Long houseId){
		RenovateRequisitionVO  renovateRequisitionVO = renovateManageService.getRequisitionOutline(houseId);

		if(renovateSupervisionService.isViolation(renovateRequisitionVO.getRenovateLicenceId())) {
				StringBuffer jsonStr=new StringBuffer("{");

				jsonStr.append("\"burdenMan\" : \""+ (renovateRequisitionVO.getBurdenMan()==null ? "" : renovateRequisitionVO.getBurdenMan())+"\",");
				jsonStr.append("\"renovateLicenceNO\":\"" + (renovateRequisitionVO.getRenovateLicenceNO() ==null ? "" : renovateRequisitionVO.getRenovateLicenceNO()) +"\",");
				jsonStr.append("\"renovateLicenceId\":\"" + (renovateRequisitionVO.getRenovateLicenceId() ==null ? "" : renovateRequisitionVO.getRenovateLicenceId()) +"\",");
				jsonStr.append("\"burdenManPhone\" : \""+ (renovateRequisitionVO.getBurdenManPhone()==null ? "" : renovateRequisitionVO.getBurdenManPhone()) +"\",");
				jsonStr.append("\"owner\" : \""+ (renovateRequisitionVO.getClientNames()==null ? "" : renovateRequisitionVO.getClientNames()) +"\",");
				jsonStr.append("\"linkMan\" : \""+ (renovateRequisitionVO.getLinkman()==null ? "" : renovateRequisitionVO.getLinkman()) +"\",");
				jsonStr.append("\"linkManPhone\" : \""+ (renovateRequisitionVO.getLinkManPhone()==null ? "" : renovateRequisitionVO.getLinkManPhone()) +"\"");
				jsonStr.append("}");
				this.renderText(jsonStr.toString());
			}
	}


	/***
	 * 功能描述:  新增违规登记<br>
	 *
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void addRenovateViolation(@Read RenovateViolationVO renovateViolationVO){
		renovateViolationVO.setCreator(this.getUserId());
		renovateSupervisionService.addRenovateViolation(renovateViolationVO);
		this.renderText("true");
	}

	/***
	 * 功能描述:  初始化修改违规登记<br>
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initRenovateViolationEdit(@Read(key="renovateViolationId")Long id){
		RenovateViolationVO violationVO = renovateSupervisionService.getRenovateViolation(id);
		setAttribute("violation", violationVO);
		setAttribute("flag", "update");
		return "renovateViolationEdit";
	}

	/***
	 * 功能描述:  修改违规登记<br>
	 *
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void editRenovateViolation(@Read RenovateViolationVO renovateViolationVO){
		renovateViolationVO.setModifier(this.getUserId());
		renovateSupervisionService.editRenovateViolation(renovateViolationVO);
		this.renderText("true");
	}

	/***
	 * 功能描述: 删除违规登记 <br>
	 * @param renovateViolationId
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void deleteRenovateViolation(@Read(key="renovateViolationId")Long renovateViolationId){
		renovateSupervisionService.deleteRenovateViolation(renovateViolationId);
		this.renderText("true");
	}

	/***
	 * 功能描述:  获取违规登记详细信息<br>
	 * @param id
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String getRenovateViolationDetail(@Read(key="renovateViolationId")Long id){
		RenovateViolationVO renovateViolationVO = renovateSupervisionService.getRenovateViolation(id);
		setAttribute("renovateViolation", renovateViolationVO);
		return "renovateViolationDetail";
	}

	/***
	 * 功能描述: 初始化整改主界面 <br>
	 * @param id
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-22  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initReformMain(@Read(key="renovateViolationId")Long id){
		setAttribute("renovateViolationId", id);
		return "reformMain";
	}

	/***
	 * 功能描述:  整改验收列表<br>
	 * @param pageNO
	 * @param pageSize
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initReformList(
			@Read(key="renovateViolationId") Long renovateViolationId){
//		,
//		@Read(key = "ec_p", defaultValue = "1") Integer pageNO,
//		@Read(key = "ec_crd",defaultValue = "7")Integer pageSize
		List<ReformVO> list = renovateSupervisionService.getReforms(renovateViolationId);
		if(!BlankUtil.isBlank(list)){
			setAttribute("reformList", list);
			setAttribute("totalRows",Integer.valueOf(list.size()));
		}else{
			setAttribute("totalRows",new Integer(0));
		}
		return "reformList";
	}

	public String initReformSampleList(@Read(key="renovateViolationId") Long renovateViolationId){
		List<ReformVO> list = renovateSupervisionService.getReforms(renovateViolationId);
		if(!BlankUtil.isBlank(list)){
			setAttribute("reformList", list);
			setAttribute("totalRows",Integer.valueOf(list.size()));
		}else{
			setAttribute("totalRows",new Integer(0));
		}
		return "reformSampleList";
	}
	/***
	 * 功能描述: 初始化新增整改验收 <br>
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String initReformAdd(@Read(key="id")Long id){
		RenovateViolationVO renovateViolationVO = renovateSupervisionService.getRenovateViolation(id);
		setAttribute("renovate", renovateViolationVO);
		return "reformAdd";
	}


	/***
	 * 功能描述:  新增整改验收<br>
	 *
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void addReform(@Read ReformVO reformVO){
		reformVO.setCreator(this.getUserId());
		renovateSupervisionService.addReform(reformVO);
		this.renderText("true");
	}

	/**
	 * 功能描述:  删除整改验收<br>
	 * @param id
	 * Create author:yandawei <br>
	 * Create on:2008-12-19  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void deleteReform(@Read(key="reformId")Long reformId){
		renovateSupervisionService.deleteReform(reformId);
		this.renderText("true");
	}

	public void setRenovateSupervisionService(
			IRenovateSupervisionService renovateSupervisionService) {
		this.renovateSupervisionService = renovateSupervisionService;
	}

	public void setBuildingService(IBuildingService buildingService) {
		this.buildingService = buildingService;
	}

	public void setRenovateManageService(
			IRenovateManageService renovateManageService) {
		this.renovateManageService = renovateManageService;
	}




}
